library speech_sapi;

uses CoreI, MSSapi5, SpeechI;

  var PluginInfo:PPluginInfo;
sapi5:TSpVoice;
procedure SpeakText(const str:PWideChar); cdecl;
begin
SAPI5.DefaultInterface.Speak(str, SVSFlagsAsync);
end;

Procedure SetRate(rate:integer); cdecl;
begin
if rate > 100 then rate := 100
else if rate < 0 then rate := 0;
sapi5.Rate := rate div 5 - 10;
      end;

      function GetRate:integer; cdecl;
      begin
result := (sapi5.Rate + 10) * 5;
end;

Procedure SetVolume(volume:integer); cdecl;
begin
if (volume < 0) then volume := 0
else if (volume> 100) then volume := 100;
sapi5.Volume := volume;
end;

function GetVolume:integer; cdecl;
begin
result := sapi5.Volume;
end;
      procedure Init; cdecl;
begin
try
            Sapi5:=TSpVoice.Create;
            except
core_Error('Sapi5 Initialization failed.', ECORE_INIT);
            end;
            end;

procedure Free; cdecl;
begin
sapi5.Free;
dispose(ISpeech(PluginInfo^.InterfaceStruct));
dispose(PluginInfo);
end;

Procedure Plugin_GetInfo(var info:PPluginInfo; var length:cardinal); cdecl;
begin
length := 1;
new (pluginInfo);
info := pluginInfo;
info^.GUID := SpeechGUID;
info^.Name := 'speech_SAPI';
info^.Init := Init;
info^.free := Free;
new(ISpeech(info^.InterfaceStruct));
ISpeech(Info^.InterfaceStruct)^.SpeakText := SpeakText;
ISpeech(Info^.InterfaceStruct)^.SetRate := SetRate;
ISpeech(Info^.InterfaceStruct)^.GetRate := GetRate;
ISpeech(Info^.InterfaceStruct)^.SetVolume := SetVolume;
ISpeech(Info^.InterfaceStruct)^.GetVolume := GetVolume;
end;
exports Plugin_GetInfo;
begin
end.
